package com.hsqn.controller;

import com.hsqn.service.ElderlyService;
import hsqn.pojo.AlarmInfo;
import hsqn.pojo.Elderly;
import hsqn.pojo.HealthRecord;
import hsqn.pojo.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

// 找一个 IDEA注释模版
@RequestMapping("elderly")
@RestController
@Tag(name="老人管理")
public class ElderlyController {

    HealthRecord healthRecord1=new HealthRecord();
    @Autowired
    private ElderlyService elderlyService;
   @PostMapping("addElderly")
   @Operation(summary = "添加老人", description = "添加老人",
   responses = {
           @ApiResponse(description = "成功", responseCode = "200",
           content = @Content(schema = @Schema(implementation = Result.class))),
           @ApiResponse(description = "失败", responseCode = "400")
   })
   public Result addElderly(@Parameter(name = "elderly",description = "老人信息")@RequestBody Elderly elderly){
       if(elderlyService.addElderly(elderly)!=null){
           healthRecord1.setElderlyId(elderly.getId());
           return Result.success();
       }
       return Result.success("添加失败");
   }



   @PutMapping("upElderly")
   @Operation(summary = "更新添加老人亲属", description = "更新添加老人亲属",
   responses = {
           @ApiResponse(description = "成功", responseCode = "200",
           content = @Content(schema = @Schema(implementation = Result.class))),
           @ApiResponse(description = "失败", responseCode = "400")
   })
    public Result updateElderly(@Parameter(name = "elderly",description = "添加老人亲属")@RequestBody Elderly elderly){
       elderlyService.updateElderly(elderly);
       return Result.success();
   }


   @PostMapping("addHealthRecord")
   @Operation(summary = "添加健康档案", description = "添加健康档案",
   responses = {
           @ApiResponse(description = "成功", responseCode = "200",
           content = @Content(schema = @Schema(implementation = Result.class))),
           @ApiResponse(description = "失败", responseCode = "400")
   })
    public Result addHealthRecord(@Parameter(name = "healthRecord",description = "添加健康档案")@RequestBody HealthRecord healthRecord){
       healthRecord.setElderlyId(healthRecord1.getElderlyId());
       elderlyService.addHealthRecord(healthRecord);
       return Result.success();
   }


   @PutMapping("alarm")
   @Operation(summary = "添加实时健康数据", description = "记录血压、血糖",
   responses = {
           @ApiResponse(description = "成功", responseCode = "200",
           content = @Content(schema = @Schema(implementation = Result.class))),
           @ApiResponse(description = "失败", responseCode = "400")
   })
    public Result upAlarm(@Parameter(name = "healthRecord",description = "添加实时健康数据")@RequestBody HealthRecord healthRecord){
        elderlyService.upHealthRecord(healthRecord);
        return Result.success();
   }


   @PutMapping("upEvaluation")
    @Operation(summary = "更新评估结果", description = "更新评估结果",
   responses = {
           @ApiResponse(description = "成功", responseCode = "200",
           content = @Content(schema = @Schema(implementation = Result.class))),
           @ApiResponse(description = "失败", responseCode = "400")
   })
    public Result upEvaluation(@Parameter(name = "healthRecord",description = "更新评估结果")@RequestBody HealthRecord healthRecord){
       elderlyService.upEvaluation(healthRecord);
       return Result.success();
   }


   @PostMapping("addAlarm")
    @Operation(summary = "添加报警信息", description = "添加报警信息",
   responses = {
           @ApiResponse(description = "成功", responseCode = "200",
           content = @Content(schema = @Schema(implementation = Result.class))),
           @ApiResponse(description = "失败", responseCode = "400")
   })
    public Result addAlarm(){
      elderlyService.addAlarm();
       return Result.success();
   }



   @PostMapping("addLocationInfo")
    @Operation(summary = "添加位置信息", description = "添加位置信息",
   responses = {
           @ApiResponse(description = "成功", responseCode = "200",
           content = @Content(schema = @Schema(implementation = Result.class))),
           @ApiResponse(description = "失败", responseCode = "400")
   })
    public Result addLocationInfo(){
       elderlyService.addLocationInfo();
       return Result.success();
   }


   @PostMapping("addAlarmInfo")
    @Operation(summary = "插入警告记录",description = "插入警告记录",
    responses = {
            @ApiResponse(description = "成功",responseCode = "200",
            content = @Content(schema = @Schema(implementation = Result.class))),
            @ApiResponse(description = "失败",responseCode = "400")
    })
    public Result addAlarmInfo(@Parameter(name="alarmInfo") @RequestBody AlarmInfo alarmInfo){
        elderlyService.addAlarmInfo(alarmInfo);
        return Result.success();
   }


   @PutMapping("upAlarmInfo")
   @Operation(summary = "更新处理状态",description = "更新告警表的处理状态",
   responses = {
           @ApiResponse(description = "成功",responseCode = "200",
                   content = @Content(schema = @Schema(implementation = Result.class))),
           @ApiResponse(description = "失败",responseCode = "400")
   })
    public Result upAlarmInfo(@RequestBody AlarmInfo alarmInfo){
       elderlyService.  upAlarmInfo(alarmInfo);
       return Result.success();
   }





}
